/*
Copyright 2014, KISSY v1.47
MIT Licensed
build time: May 22 12:20
*/
KISSY.add("editor/plugin/drag-upload",["editor","event"],function(h,g){function k(h){this.config=h||{}}var q=g("editor"),m=g("event"),r=h.Node,s=q.Utils,l=h.DOM;h.augment(k,{pluginRenderUI:function(g){function k(b){b=b.originalEvent.target;"img"===l.nodeName(b)&&b.src.match(/^file:\/\//)&&(n[b.src]=b)}function t(b,d){var e=new window.FileReader;e.onload=function(f){var a=b.name,f=f.target.result,c=new XMLHttpRequest;c.open("POST",u,!0);c.onreadystatechange=function(){if(4===c.readyState){if(200===
c.status||304===c.status){if(""!==c.responseText){var a=h.parseJson(c.responseText);d[0].src=a.imgUrl}}else window.alert("\u670d\u52a1\u5668\u7aef\u51fa\u9519\uff01"),d.remove();c.onreadystatechange=null}};a="\r\n------kissy-editor-yiminghe\r\n"+("Content-Disposition: form-data; name='"+v+"'; filename='"+encodeURIComponent(a)+"'\r\n");a+="Content-Type: "+(b.type||"application/octet-stream")+"\r\n\r\n";a+=f+"\r\n";o=q.Utils.normParams(o);for(var j in o)a+="------kissy-editor-yiminghe\r\n",a+="Content-Disposition: form-data; name='"+
j+"'\r\n\r\n",a+=o[j]+"\r\n";a+="------kissy-editor-yiminghe--";c.setRequestHeader("Content-Type","multipart/form-data, boundary=----kissy-editor-yiminghe");c.sendAsBinary("Content-Type: multipart/form-data; boundary=----kissy-editor-yiminghe\r\nContent-Length: "+a.length+"\r\n"+a+"\r\n");e.onload=null};e.readAsBinaryString(b)}var i=this.config,v=i.fileInput||"Filedata",w=i.sizeLimit||Number.MAX_VALUE,o=i.serverParams||{},u=i.serverUrl||"",x=RegExp((i.suffix||"png,jpg,jpeg,gif").split(/,/).join("|")+
"$","i"),n={},p=!1;g.docReady(function(){var b=g.get("document")[0];m.on(b,"dragenter",function(){p||(m.on(b,"DOMNodeInserted",k),p=!0)});m.on(b,"drop",function(d){m.remove(b,"DOMNodeInserted",k);p=!1;d.halt();var d=d.originalEvent,e,f;h.isEmptyObject(n)?(f=b.elementFromPoint(d.clientX,d.clientY),e=f.lastChild):(h.each(n,function(a){"img"===l.nodeName(a)&&(e=a.nextSibling,f=a.parentNode,l.remove(a))}),n={});d=d.dataTransfer;d.dropEffect="copy";if(d=d.files)for(var a=0;a<d.length;a++){var c=d[a],j=
c.size;if(c.name.match(x)&&!(j/1E3>w)){var j=new r('<img src="'+s.debugUrl("theme/tao-loading.gif")+'"/>'),g=j[0];f.insertBefore(g,e);var i=l.nodeName(g.parentNode);("head"===i||"html"===i)&&l.insertBefore(g,b.body.firstChild);t(c,j)}}})});window.XMLHttpRequest&&!XMLHttpRequest.prototype.sendAsBinary&&(XMLHttpRequest.prototype.sendAsBinary=function(b,d){var e;e=window.BlobBuilder?new window.BlobBuilder:window.WebKitBlobBuilder();for(var f=b.length,a=new window.Uint8Array(f),c=0;c<f;c++)a[c]=b.charCodeAt(c);
e.append(a.buffer);this.send(e.getBlob(d))})}});return k});
